﻿param(
    [Parameter(Mandatory=$true)]
    [ValidateNotNullOrEmpty()]
    [string]
    $UserName,

    [Parameter(Mandatory=$true)]
    [ValidateNotNullOrEmpty()]
    [string]
    $Password,

    [Parameter(Mandatory=$true)]
    [ValidateNotNullOrEmpty()]
    [string]
    $ClientId,

    [Parameter(Mandatory=$true)]
    [ValidateNotNullOrEmpty()]
    [string]
    $ClientSecret,

    [Parameter(Mandatory=$true)]
    [ValidateNotNullOrEmpty()]
    [string]
    $Scope,

    [Parameter(Mandatory=$true)]
    [ValidateNotNullOrEmpty()]
    [string]
    $RepositoryName,

    [Parameter(Mandatory=$true)]
    [ValidateNotNullOrEmpty()]
    [string]
    $Owner,

    [Parameter(Mandatory=$true)]
    [ValidateNotNullOrEmpty()]
    [string]
    $RepositoryDirectory,

    [ValidateNotNullOrEmpty()]
    [string]
    $Method = "pull",

    [ValidateNotNullOrEmpty()]
    [string[]]
    $IgnorePaths = @(),

    [bool]
    $CleanAfterPush,

    [bool]
    $CleanAfterPull
)

Write-Host "change workspace to $($PSScriptRoot)"
Set-Location $PSScriptRoot

. .\GiteeProject.ps1
. .\GiteeUser.ps1

$userToken = Get-UserToken `
 -UserName $($UserName) `
 -Password $($Password) `
 -ClientId $($ClientId)`
 -ClientSecret $($ClientSecret) `
 -Scope $($Scope)

$project = [GiteeProject]::new($userToken.access_token, $RepositoryName, $Owner)

if ($Method -eq "pull")
{
    $project.Pull($RepositoryDirectory, $IgnorePaths, $CleanAfterPull)
}
else
{
    $project.Push($RepositoryDirectory, $IgnorePaths, $CleanAfterPush)
}
